<?

if (!function_exists('inOwnSubmenu')) {
	function inOwnSubmenu($menuId) {
		global $DATA;
		
		if ($menuId && isset($DATA['menus'][$menuId]) && sizeof($_m2 = $DATA['menus'][$menuId]['name']) && is_array($_menu2 = $DATA['menu'][$_m2]) && sizeof($_menu2)) {
			foreach($_menu2 as $id2 => $v2)
				if (inCrumb($v2['value']))
					return true;
		}
		
		return false;
	}
}

if (!function_exists('basicMenuShow')) {
	function basicMenuShow($_menu, $levels, $current) {

		foreach($_menu as $id => $v) {
			
			$class = array("level$current", $v['first'], $v['last'], "item$id");

			if ($p = inCrumb($v['value'])) $class[] = "incrumb$current";

//debug($x = array($p, $class, $GLOBALS['DATA']['crumb']))
	
			?><li class="<?=implode(' ', array_trim_empty($class))?>"><?
			
			if ($p && $p['last']) { 
				?><strong><?=t($v['name'], 'menu')?><?=$v['text'] ? "<span class=\"description\">$v[text]</span>" : ''?></strong><?
			} else { 
				?><a href="<?=$v['value']?>" title="<?=$v['text']?>" class="level1"><?=t($v['name'], 'menu')?><?=$v['text'] ? "<span class=\"description\">$v[text]</span>" : ''?></a><? 
			} 
		
			if ($levels > $current) {
				
				if ($v['tag'] && isset($GLOBALS['DATA']['menus'][$v['tag']]) && sizeof($_m2 = $GLOBALS['DATA']['menus'][$v['tag']]['name'])) {

//					debug($_m2,'m2');


					if (is_array($_menu2 = $DATA['menu'][$_m2]) && sizeof($_menu2)) {
						
//						debug($_menu2,'menu2');
					}
				}
				
			}
	
			?></li><?
		}
		
	}
}

//debug($DATA['menu'], 'menu');
//debug($DATA['menus'], 'menus');

if (is_array($_menu = $DATA['menu'][stack('menu')]) && sizeof($_menu)) {

	basicMenuShow($_menu, stack('levels', 1), 1);

/*	foreach($_menu as $id => $v) {
	
		$first = ($v['first']) ? ' first' : '';
		$last = ($v['last']) ? ' last' : '';

//debug($x = array($v, inCrumb($v['value']) ? "true" : "false", $p['last'] ? "true" : "false", $v['tag'], inOwnSubmenu($v['tag']) ? "true" : "false"));

		if (($p = inCrumb($v['value'])) && ($p['last'] || inOwnSubmenu($v['tag'])) ) { 
			?><li class="level1 incrumb<?=$first.$last?>"><?
	
			if ($p['last']) {
				?><strong><span><?=$v['name']?></span></strong><?
			} else { 
				?><a href="<?=$v['value']?>" title="<?=$v['text']?>" class="level1"><span><?=$v['name']?></span></a><? 
			} 
	
		} else {
			?><li class="level1<?=$first.$last?>"><a href="<?=$v['value']?>" title="<?=$v['text']?>"><span><?=$v['name']?></span></a><?
		}
		
		if (stack('levels', 1) > 1) { 
			
			if (isset($DATA['menus'][$v['tag']]) && sizeof($_m2 = $DATA['menus'][$v['tag']]['name'])) {

				if (is_array($_menu2 = $DATA['menu'][$_m2]) && sizeof($_menu2)) {
					
					?><ul class="level2"><?
				
					foreach($_menu2 as $id2 => $v2) {
					
						$first = ($v2['first']) ? ' first' : '';
						$last = ($v2['last']) ? ' last' : '';
						
						if ($p = inCrumb($v2['value'])) { 
							?><li class="level2 incrumb2<?=$first.$last?>"><?
					
							if ($p['last']) {
								?><strong><span><?=$v2['name']?></span></strong><?
							} else { 
								?><a href="<?=$v2['value']?>" title="<?=$v2['text']?>" class="level2"><span><?=$v2['name']?></span></a><? 
							} 
					
						} else {
							?><li class="level2<?=$first.$last?>"><a href="<?=$v2['value']?>" title="<?=$v2['text']?>"><span><?=$v2['name']?></span></a><?
						}
							// place level3 here %)
							
						?></li><?
						
					}
					
					?></ul><?

				}
			}


		}
		
		?></li><?
		
	}
*/
}

unstack();
?>

